package com.roncoo.education.system.service.admin.biz;

import com.roncoo.education.common.service.BaseBiz;
import com.roncoo.education.common.core.base.Page;
import com.roncoo.education.common.core.base.PageUtil;
import com.roncoo.education.common.core.base.Result;
import com.roncoo.education.common.core.tools.BeanUtil;
import com.roncoo.education.system.service.admin.req.AdminMinioUploadingEditReq;
import com.roncoo.education.system.service.admin.req.AdminMinioUploadingPageReq;
import com.roncoo.education.system.service.admin.req.AdminMinioUploadingSaveReq;
import com.roncoo.education.system.service.admin.resp.AdminMinioUploadingPageResp;
import com.roncoo.education.system.service.admin.resp.AdminMinioUploadingViewResp;
import com.roncoo.education.system.dao.MinioUploadingDao;
import com.roncoo.education.system.dao.impl.mapper.entity.MinioUploading;
import com.roncoo.education.system.dao.impl.mapper.entity.MinioUploadingExample;
import com.roncoo.education.system.dao.impl.mapper.entity.MinioUploadingExample.Criteria;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

import javax.validation.constraints.NotNull;

/**
 * ADMIN-
 *
 * @author wujing
 */
@Component
@RequiredArgsConstructor
public class AdminMinioUploadingBiz extends BaseBiz {

    @NotNull
    private final MinioUploadingDao dao;

    /**
     * 分页
     *
     * @param req 分页查询参数
     * @return 分页查询结果
     */
    public Result<Page<AdminMinioUploadingPageResp>> page(AdminMinioUploadingPageReq req) {
        MinioUploadingExample example = new MinioUploadingExample();
        Criteria c = example.createCriteria();
        Page<MinioUploading> page = dao.page(req.getPageCurrent(), req.getPageSize(), example);
        Page<AdminMinioUploadingPageResp> respPage = PageUtil.transform(page, AdminMinioUploadingPageResp.class);
        return Result.success(respPage);
    }

    /**
     * 添加
     *
     * @param req 
     * @return 添加结果
     */
    public Result<String> save(AdminMinioUploadingSaveReq req) {
        MinioUploading record = BeanUtil.copyProperties(req, MinioUploading.class);
        if (dao.save(record) > 0) {
            return Result.success("操作成功");
        }
        return Result.error("操作失败");
    }

    /**
     * 查看
     *
     * @param id 主键ID
     * @return 
     */
    public Result<AdminMinioUploadingViewResp> view(String id) {
        return Result.success(BeanUtil.copyProperties(dao.getById(id), AdminMinioUploadingViewResp.class));
    }

    /**
     * 修改
     *
     * @param req 修改对象
     * @return 修改结果
     */
    public Result<String> edit(AdminMinioUploadingEditReq req) {
        MinioUploading record = BeanUtil.copyProperties(req, MinioUploading.class);
        if (dao.updateById(record) > 0) {
            return Result.success("操作成功");
        }
        return Result.error("操作失败");
    }

    /**
     * 删除
     *
     * @param id ID主键
     * @return 删除结果
     */
    public Result<String> delete(String id) {
        if (dao.deleteById(id) > 0) {
            return Result.success("操作成功");
        }
        return Result.error("操作失败");
    }
}
